package com.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.entity.Visitorsuser1;
import com.service.Visitorsuser1Service;

@Controller
@RequestMapping("/visitorsuser")
public class Visitorsuser1Controller {
	@Resource
	Visitorsuser1Service visitorsuserService;
	/**
	 * 添加账号
	 * @param request
	 * @param visitorsuser
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/insert")
	public String insert(HttpServletRequest request,Visitorsuser1 visitorsuser){
		String openid=request.getParameter("openid");
		visitorsuser.setOpenid(openid);
		int num=visitorsuserService.insert(visitorsuser);
		if(num==1){
			return "1";
		}else{
			return "0";
		}
	}
	@ResponseBody
	@RequestMapping("/select")
	public String select(HttpServletRequest request,ModelMap modelMap){
		String openid=request.getParameter("openid");
		System.out.println("openid=="+openid);
		List<Visitorsuser1> list=visitorsuserService.select(openid);
		modelMap.addAttribute("list", list);
		new JSONObject();
		JSONObject json=JSONObject.fromObject(modelMap);
		System.out.println(json.toString());
		return json.toString();
	}
}
